import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;

import javax.swing.JButton;
import javax.swing.SwingConstants;
import javax.swing.JTextField;
import java.awt.event.ActionListener;
import java.util.Random;
import java.awt.event.ActionEvent;

public class ARMSample extends JFrame {

	private JPanel contentPane;
	private JTextField txtTest;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ARMSample frame = new ARMSample();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
	com.jacob.activeX.ActiveXComponent arm;

	/**
	 * Create the frame.
	 */
	public ARMSample() {
		arm = new ActiveXComponent("ARM.ARMClass");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		
		JPanel panel = new JPanel();
		contentPane.add(panel, BorderLayout.NORTH);
		
		JButton btnNewButton = new JButton("New button");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				Random rnd = new Random();
				
				int Rnd1 = rnd.nextInt(2000000)+1;
				com.jacob.com.Variant va = new Variant(Rnd1);
				com.jacob.com.SafeArray vtest = Dispatch.call(arm, "Authenticate", va).toSafeArray();
				byte[] b = vtest.toByteArray();
				txtTest.setText(new String(b));
			}
		});
		btnNewButton.setVerticalAlignment(SwingConstants.TOP);
		btnNewButton.setHorizontalAlignment(SwingConstants.TRAILING);
		panel.add(btnNewButton);
		
		txtTest = new JTextField();
		panel.add(txtTest);
		txtTest.setColumns(10);
	}

}
